package org.nlp2rdf.navigator.benchmark;

import org.aksw.commons.util.collections.TransformCollection;
import org.apache.commons.collections15.Transformer;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by Claus Stadler
 * Date: Oct 12, 2010
 * Time: 5:51:10 PM
 */
public class WrapperGenericClassifier<I, O, D>
    implements IGenericClassifier<I, D>
{
    private IGenericClassifier<O, D> decoratee;
    private Transformer<O, I> transformer;

    public WrapperGenericClassifier(IGenericClassifier<O, D> decoratee, Transformer<O, I> transformer)
    {
        this.decoratee = decoratee;
        this.transformer = transformer;
    }

    @Override
    public Set<I> classify(D description)
            throws Exception
    {
        Set<O> tmp = decoratee.classify(description);
        if(tmp == null)
            return null;

        Set<I> result = new HashSet<I>(new TransformCollection<O, I>(tmp, transformer));

        return result;
    }

    @Override
    public int countInstances(D description)
            throws Exception
    {
        return decoratee.countInstances(description);
    }
}
